home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / help_jr / ode < prev    next >
Text File  |  1995-05-30  |  4KB  |  142 lines

  1. ode:
  2.  
  3. Syntax:    ode ( rhsf, tstart, tend, ystart, dtout, relerr, abserr, uout )
  4.  
  5. Synopsis:       Integrate a system of first order differential
  6.             equations. 
  7.  
  8. Description:
  9.  
  10.         ode integrates a system of N first order ordinary
  11.     differential equations of the form: 
  12.  
  13.                 dy(i)/dt = f(t,y(1),y(2),...,y(N))
  14.                 y(i) given at  t .
  15.  
  16.         The arguments to ode are:
  17.  
  18.         rhsf    A function that evaluates dy(i)/dt at t. The function
  19.                 takes two arguments and returns dy/dt. An example that
  20.                 generates dy/dt for Van der Pol's equation is shown
  21.                 below. 
  22.  
  23.                 vdpol = function ( t , x ) 
  24.                 {
  25.                   local (xp)
  26.                   xp = zeros(2,1);
  27.                   xp[1] = x[1] * (1 - x[2]^2) - x[2];
  28.                   xp[2] = x[1];
  29.                   return xp;
  30.                 };
  31.  
  32.     ystart    The initial values of y, y(tstart).
  33.  
  34.         tstart  The initial value of the independent variable.
  35.  
  36.         tend    The final value of the independent variable.
  37.  
  38.         dtout   The output interval. The vector y will be saved at
  39.                 tstart, increments of tstart + dtout, and tend. If
  40.                 dtout is not specified, then the default is to store
  41.                 output at 101 values of the independent variable.
  42.  
  43.         relerr  The relative error tolerance. Default value is 1.e-6.
  44.  
  45.         abserr  The absolute error tolerance. At each step, ode
  46.                 requires that:
  47.  
  48.                 abs(local error) <= abs(y)*relerr + abserr
  49.                 
  50.                 For each component of the local error and solution
  51.                 vectors. The default value is 1.e-6.
  52.  
  53.  
  54.     uout    Optional. A user-supplied function that computes an
  55.         arbitrary output during the integration. uout must
  56.         return a row-matrix at each dtout during the
  57.         integration. It is entirely up to the user what to put
  58.         in the matrix. The matrix is used to build up a larger
  59.         matrix of the output, with one row for each dtout. The
  60.         resulting matrix is returned by ode when the
  61.         integration is complete.
  62.  
  63.     The Fortran source code for ode() is completely explained and
  64.     documented in the text, "Computer Solution of Ordinary
  65.     Differential Equations: The Initial Value Problem" by 
  66.     L. F. Shampine and  M. K. Gordon.
  67.  
  68.     Example:
  69.  
  70.     //-----------------------------------------------------------//
  71.     //  Integrate the Van der Pol equation, and measure the effect
  72.     //  of relerr and abserr on the solution.
  73.     //
  74.     
  75.     vdpol = function ( t , x ) 
  76.     {
  77.       local (xp)
  78.       xp = zeros(2,1);
  79.       xp[1] = x[1] * (1 - x[2]^2) - x[2];
  80.       xp[2] = x[1];
  81.       return xp;
  82.     };
  83.     
  84.     t0 = 0;
  85.     tf = 10;
  86.     x0 = [0; 0.25];
  87.     dtout = 0.05;
  88.     
  89.     relerr = [1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1];
  90.     abserr = relerr;
  91.     
  92.     //
  93.     //  Baseline
  94.     //
  95.     
  96.     xbase = ode( vdpol, x0, 0, 20, 0.05, 1e-9, 1e-9);
  97.     results = zeros (relerr.n, abserr.n);
  98.     elapse = zeros (relerr.n, abserr.n);
  99.     
  100.     //
  101.     // Now loop through the combinations of relerr
  102.     // and abserr, saving the results, and computing
  103.     // the maximum difference.
  104.     //
  105.  
  106.     "start testing loop"
  107.     for (i in 1:abserr.n)
  108.     {
  109.       xode.[i] = <<>>;
  110.       for (j in 1:relerr.n)
  111.       {
  112.         printf("\t%i %i\n", i, j);
  113.         tic();
  114.         xode.[i].[j] = ode( vdpol, 0, 20, x0, 0.05, relerr[j], abserr[i]);
  115.         elapse[i;j] = toc();
  116.     
  117.         // Save results
  118.         results[i;j] = max (max (abs (xode.[i].[j] - xbase)));
  119.       }
  120.     }
  121.  
  122.     //-----------------------------------------------------------//
  123.  
  124.  
  125.     > results
  126.      results =
  127.      matrix columns 1 thru 6
  128.      1.97e-05   0.000297   0.000634    0.00815      0.078       1.44  
  129.      0.000128   7.89e-05   0.000632    0.00924     0.0732       1.61  
  130.      0.000647   0.000625    0.00112     0.0147     0.0995       1.46  
  131.       0.00355    0.00352    0.00271     0.0118     0.0883      0.862  
  132.        0.0254     0.0254     0.0254      0.104      0.218       1.72  
  133.         0.513      0.513      0.513      0.589      0.467       1.82  
  134.  
  135.  
  136.     Each row of results is a function of the absolute error
  137.     (abserr) and each column is a function of the relative error
  138.     (relerr).
  139.  
  140.  
  141. See Also: ode4
  142.